<?php
	/**
	* 
	*/
	class carinfoModel{

		public $_table = 'carinfo';//设置表名
		public $_carid = '';//新添加数据id
		
		//获取数据总数
		function count(){
			$sql = 'select count(*) from '.$this -> _table;
			return DB::findResult($sql, 0, 0);
		}
		
		//取一条车辆信息
		public function getcarinfo($carid){
			if(!empty($carid)){
				$carid = intval($carid);
				$sql = 'select * from '.$this -> _table.' where id='.$carid;
				return DB::findOne($sql);
			}else{
				return array();
			}
		}

		//提交验证程序
		function carsubmit($data){
			extract($data);
			if(empty($vehicleCodePrefix)||empty($out_date)){
				return 0;
			}
			$data = array(
				'vehicleCodePrefix' => addslashes($vehicleCodePrefix),  'car_code' 				=> addslashes($car_code),
				'vehicleCardColor'  => addslashes($vehicleCardColor), 	'vehicleProperty'	 	=> addslashes($vehicleProperty),
				'vehicleType' 		=> addslashes($vehicleType), 		'vehicleBodyColor' 		=> addslashes($vehicleBodyColor),
				'vehicleDegreeType' => addslashes($vehicleDegreeType),  'vehicleGrade'			=> addslashes($vehicleGrade),
				'vehicleOilType' 	=> addslashes($vehicleOilType), 	'vehicleModel' 			=> addslashes($vehicleModel),
				'car_length' 		=> addslashes($car_length), 		'car_width' 			=> addslashes($car_width),
				'car_height' 		=> addslashes($car_height), 		'total_seat' 			=> addslashes($total_seat),
				'checked_seat' 		=> addslashes($checked_seat), 		'total_ton' 			=> addslashes($total_ton),
				'checked_ton' 		=> addslashes($checked_ton), 		'driving_license_date' 	=> addslashes($driving_license_date),
				'engine_code' 		=> addslashes($engine_code), 		'car_shelf_code' 		=> addslashes($car_shelf_code),
				'approval_number' 	=> addslashes($approval_number), 	'operation_value' 		=> addslashes($operation_value),
				'operation_property'=> addslashes($operation_property), 'vin_code' 				=> addslashes($vin_code),
				'dipper_install' 	=> addslashes($dipper_install), 	'tachographs_install' 	=> addslashes($tachographs_install),
				'vehicleDischarge'  => addslashes($vehicleDischarge), 	'purchase_invoice' 		=> addslashes($purchase_invoice),
				'purchase_date' 	=> addslashes($purchase_date), 		'production_date' 		=> addslashes($production_date),
				'out_date' 			=> addslashes($out_date), 			'car_manufacturer' 		=> addslashes($car_manufacturer),
				'stop_days' 		=> addslashes($stop_days)
				);
			if($_POST['carid'] != ''){
				DB::update($this -> _table, $data, 'id='.$carid);
				return 2;
			}else{
				DB::insert($this -> _table, $data);
				return 1;
			}
		}

		//查找所有新闻并根据时间排序
		function findAll_orderby_dataline($page){
			$sql = 'select * from '.$this -> _table.' limit '.$page.', 10';  
			return DB::findAll($sql);
		}

		//删除车辆信息
		function del_by_id($carid){
			return DB::del($this -> _table, 'id='.$carid);
		}

		//取一组车辆信息
		function get_carinfo_list($page=0){
			$data = $this ->findAll_orderby_dataline($page*10);
			return $data;
		}

		//累加添加一个数据
		public function updatacarid($carpic, $id){
			$sql = "update ".$this -> _table." set car_pic = CONCAT(car_pic,'".$carpic."') where id = ".$id;
			DB::query($sql);
			return $id;
		}
		
		//添加一个数据
		public function setcarid($carpic){
			//preg_match( '/(\d+\.?\d+)/', "'".DB::findResult("select max(id) from carinfo;")."'", $id);
			//var_dump($id);
			$id = DB::findResult("select max(id) from carinfo;");
			if($carpic){
				$sql = "update ".$this -> _table." set car_pic = '".$carpic."' where id = ".$id;
				DB::query($sql);
			}
			return $id;
		}
		
		//添加一个数据
		public function setcarstatus($carpic){
			$id = intval($_GET['carid']);
			$sql = "update ".$this -> _table." set car_status = ".$carpic." where id = ".$id;
			return DB::query($sql);
		}
		
		//删除指定字段数据中的xx值
		public function delcarid($carpic, $id){
			$sql = 'update '.$this -> _table." set car_pic = replace(car_pic,'".$carpic."','') where id = ".$id;
			return $this -> _carid;
		}
		
	}//update carinfo set car_status = 1 where id = 25
?>